package com.sky.rabc.controller;

import com.sky.rabc.config.JsonResult;
import com.sky.rabc.dto.AddNewBackUserDTO;
import com.sky.rabc.dto.BackUserLoginDTO;
import com.sky.rabc.dto.UpdateBackUserDTO;
import com.sky.rabc.service.impl.BackUserServiceImpl;
import com.sky.rabc.vo.LoginInfoResultVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 用户相关接口
 *
 * @author 刘泓君
 * @className BackUserController
 * @description 用户相关接口
 * @date 2024/6/20
 */
@RestController
@RequestMapping("back-user")
public class BackUserController {
    @Resource
    private BackUserServiceImpl backUserService;

    /**
     * 登录
     *
     * @param backUserLoginDTO 用户登录
     * @return LoginInfoResultVO 用户信息及权限信息
     */
    @PostMapping("/login")
    public JsonResult<LoginInfoResultVO> BackLogin(@RequestBody BackUserLoginDTO backUserLoginDTO) {
        LoginInfoResultVO loginInfoResultVO = backUserService.login(backUserLoginDTO);
        return JsonResult.ok(loginInfoResultVO);
    }

    /**
     * 新增后台用户
     *
     * @return Void
     */
    @PostMapping("/add-new")
    public JsonResult<Void> AddNew(@RequestBody AddNewBackUserDTO addNewBackUserDTO) {
        backUserService.addNew(addNewBackUserDTO);
        return JsonResult.ok();
    }

    /**
     * 删除用户
     *
     * @param id 用户id
     * @return Void
     */
    @GetMapping("/delete/{id:[0-9]+}")
    public JsonResult<Void> delUserById(@PathVariable Long id) {
        backUserService.delUserById(id);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    public JsonResult<Void> updateUserInfoById(@RequestBody UpdateBackUserDTO updateBackUserDTO) {
        backUserService.updateUserInfoById(updateBackUserDTO);
        return JsonResult.ok();
    }
}
